
#ifndef RTTHREADINTERFACE_H
#define RTTHREADINTERFACE_H

#include "RtDefines.h"

class CRtTimeValue;

class RT_API_EXPORT IRtEvent
{
public:
	IRtEvent();
	
	virtual RtResult OnEventFire() = 0;

	virtual void OnDestorySelf();

protected:
	virtual ~IRtEvent();
};

class /*RT_API_EXPORT*/ IRtEventQueue
{
public:
	enum EPriority
	{
		EPRIORITY_HIGH,
		EPRIORITY_NORMAL,
		EPRIORITY_LOW
	};
	
	/// this function could be invoked in the different thread.
	/// like PostMessage() in Win32 API.
	virtual RtResult PostEvent(IRtEvent *aEvent, EPriority aPri = EPRIORITY_NORMAL) = 0;

	/// this function could be invoked in the different thread.
	/// like SendMessage() in Win32 API.
	virtual RtResult SendEvent(IRtEvent *aEvent) = 0;

	/// get the number of pending events.
	virtual DWORD GetPendingEventsCount() = 0;
	
protected:
	virtual ~IRtEventQueue() { }
};

/**
 * @class IRtTimerHandler
 *
 * @brief Provides an abstract interface for handling timer event.
 *
 * Subclasses handle a timer's expiration.
 * 
 */
class /*RT_API_EXPORT*/ IRtTimerHandler
{
public:
	/**
	 * Called when timer expires.  <aCurTime> represents the current
	 * time that the <IRtEventHandler> was selected for timeout
	 * dispatching and <aArg> is the asynchronous completion token that
	 * was passed in when <ScheduleTimer> was invoked.
	 * the return value is ignored.
	 */
	virtual void OnTimeout(const CRtTimeValue &aCurTime, LPVOID aArg) = 0;

protected:
	virtual ~IRtTimerHandler() { }
};

class /*RT_API_EXPORT*/ IRtTimerQueue
{
public:
	/**
	 * this function must be invoked in the own thread.
	 * <aInterval> must be greater than 0.
	 * If success:
	 *    if <aTh> exists in queue, return RT_ERROR_FOUND;
	 *    else return RT_OK;
	 */
	virtual RtResult ScheduleTimer(IRtTimerHandler *aTh, 
					  LPVOID aArg,
					  const CRtTimeValue &aInterval,
					  DWORD aCount) = 0;

	/**
	 * this function must be invoked in the own thread.
	 * If success:
	 *    if <aTh> exists in queue, return RT_OK;
	 *    else return RT_ERROR_NOT_FOUND;
	 */
	virtual RtResult CancelTimer(IRtTimerHandler *aTh) = 0;
	
protected:
	virtual ~IRtTimerQueue() { }
};

#endif // RTTHREADINTERFACE_H
